<template>
    <h2>优惠券添加</h2> 
    <table border="1">
        <tr>
            <td>劵类型</td>
            <td>
                <select v-model="info.type">
                    <option value="代金券">代金券</option>
                    <option value="折扣卷">折扣卷</option>
                    <option value="优惠券">优惠券</option>
                </select>
            </td>
        </tr>
        <tr>
            <td>代金券标题</td>
            <td>
                <input type="text" v-model="info.title"/>
            </td>
        </tr>
         <tr>
            <td>代金券副标题</td>
            <td>
                <input type="text" v-model="info.fTitle"/>
            </td>
        </tr>
         <tr>
            <td>代金券图片</td>
            <td>

                <img :src="info.imgUrl" style="width:80px;height:70px;"/>
                <input type="file" @change="Tu"/>
            </td>
        </tr>
         <tr>
            <td>剩余库存</td>
            <td>
                <input type="text" v-model="info.kuCun"/>
            </td>
        </tr>
         <tr>
            <td>每人限额</td>
            <td>
                <input type="text" v-model="info.num"/>
            </td>
        </tr>
         <tr>
            <td>使用条件</td>
            <td>
                <input type="text" v-model="info.tiaoJian"/>
            </td>
        </tr>
        <tr>
            <td>减免金额</td>
            <td>
                <input type="text" v-model="info.money"/>
            </td>
        </tr>
        <tr>
            <td>有效期</td>
            <td>
                <input type="date" v-model="info.statrTime"/>
                -
                <input type="date" v-model="info.endTime"/>
            </td>
        </tr>
        <tr>
            <td>适用业务</td>
            <td>
                <select v-model="info.yeWu">
                    <option value="订房">订房</option>
                    <option value="商城">商城</option>
                    <option value="堂食">堂食</option>
                    <option value="收款码">收款码</option>
                </select>
            </td>
        </tr>
        <tr>
            <td>使用须知</td>
            <td>
                <textarea v-model="info.xuZhi">

                </textarea>
            </td>
        </tr>
        <tr>
            <td>适用门店</td>
            <td>
                <input type="text" v-model="info.shop"/>
            </td>
        </tr>
        <tr>
            <td>服务电话</td>
            <td>
                <input type="text" v-model="info.phone"/>
            </td>
        </tr>
        <tr>
            <td>
                <input type="button" value="添加" @click="Add"/>
            </td>
        </tr>
    </table>
</template>
<script setup lang="ts">
    import {ref,onMounted} from 'vue';
    import axios from 'axios';

    const info=ref({
        type: "",
        title: "",
        fTitle: "",
        imgUrl: "",
        kuCun: 0,
        num: 0,
        tiaoJian:"",
        money: 0,
        statrTime: "",
        endTime: "",
        yeWu: "",
        xuZhi: "",
        shop: "",
        phone: ""
    });

    const Add=()=>{
        axios.post("https://localhost:7034/api/Discount/AddDiscount",info.value)
        .then(res=>{
            if(res.data>0){
                alert('添加成功');
            }
            else{
                alert('添加失败');
            }
        })
        .catch(err=>{
            console.log(err);
        })
    }

    const Tu=(e:any)=>{
        var file=e.target.files[0];
        var fd=new FormData();
        fd.append("Files",file);
        axios.post("https://localhost:7034/api/File/Tu",fd)
        .then(res=>{
            console.log(res.data);
            info.value.imgUrl=res.data;
        })
        .catch(err=>{
            console.log(err);
        })
    }

</script>